package com.seirsoft.framework.util;

import java.util.Timer;
import java.util.TimerTask;


public class ThreadUtil {
	public static class SeirSoftTimeTask extends TimerTask
	{
		private Runnable m_runner = null;
		private Timer timer = null;	
		private boolean isTimeStart = false;
		
		public SeirSoftTimeTask(Runnable runner)
		{
		    this.timer = new Timer();
		    
		    this.m_runner = runner;
		}
		
		public void start(int interval)
		{
		    this.isTimeStart = true;
			this.timer.scheduleAtFixedRate(this, 0, interval);
		}
		
		public void stop()
		{
	        if(isTimeStart)
	        {
	        	timer.cancel();
	        	timer.purge();
	        	isTimeStart = false;
	        }
		}

		@Override
		public void run() {
			if(isTimeStart)
			{
				this.m_runner.run();
			}
		}

	}
}
